package cn.tedu.controller;

import cn.tedu.assemble.WorkerAssemble;
import cn.tedu.bo.WorkerBO;
import cn.tedu.param.WorkerCreateParam;
import cn.tedu.service.WorkerService;
import cn.tedu.vo.WorkerVO;
import com.tarena.passport.protocol.LoginUser;
import com.tarena.passport.sdk.context.SecurityContext;
import com.tedu.inn.protocol.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    @Autowired
    private WorkerAssemble workerAssemble;

    @PostMapping("/worker/create")
    public Result<Long> createWorker(@RequestBody WorkerCreateParam workerCreateParam,
                                     @RequestHeader("Authorization") String authorization
    ) throws Exception{

        Long workerId = workerService.create(workerCreateParam);
        return new Result<>(workerId);
    }

    @GetMapping("/worker/detail")
    public Result<WorkerVO> detailWorker() throws Exception {
        WorkerBO workerBO=workerService.detail();
        //需要将BO转换成VO
        WorkerVO workerVO = workerAssemble.assembleBO2VO(workerBO);
        return new Result<>(workerVO);
    }


}
